cd ${work}5_reg_analysis

local ylist		"log_price"
local felist	`" "IDY FPD FPY" "'
local wlist		`" "" "'
local elist		"entry entry_first"

use temp\regsample_ipdt, clear

gen x_ols	= treated_2
gen int_ols = .
gen e_ols	= .
gen x_iv	= treated_2
gen int_iv	= .
gen e_iv	= .

lab var x_ols	"Support"
lab var int_ols	"Support $\times$ Entry"
lab var e_ols	"Entry"
lab var x_iv	"Support"
lab var int_iv	"Support $\times$ Entry"
lab var e_iv	"Entry"

eststo clear
local mtitles
local n=1
foreach e of local elist {

replace int_ols	= treated_2 * `e'
replace e_ols	= `e'
replace int_iv	= treated_2 * `e'
replace e_iv	= `e'

foreach y of local ylist {
local nfe=1	
foreach fe of local felist {
	
	local w : word `nfe' of `wlist'
	
	eststo est1: reghdfe `y' x_ols e_ols int_ols `w', a(`fe') vce(cl F) nosamp
	
	eststo est2: ivreghdfe `y' ( x_iv int_iv = tdcinitiative_2 tdcinitiative_2#`e' ) e_iv `w', a(`fe') cl(F)
	local N = e(N)
	local F = e(widstat)
	
	eststo stacked_`n' : appendmodels est1 est2
	eststo drop est*
	qui estadd scalar N `N'
	qui estadd scalar F `F'
	qui estadd local FE `fe'
	if "`w'"!=""	qui estadd local SC "Yes"
	if "`w'"==""	qui estadd local SC "No"
	local mtitles `mtitles' "`:var lab `y''"
		
	local ++n
	local ++nfe
	
}	
}
}
	
esttab using output\table_a9.tex , replace booktabs se label ///
	title("Price Distortions") star(* 0.1 ** 0.05 *** 0.01) mtitles(`mtitles') keep(x_* int_* e_*) order(e_ols x_ols int_ols e_iv x_iv int_iv) ///
	stats(N F FE SC , labels("Observations" "IV F-stat" "Fixed Effects" "Size Control") fmt(%10.0fc %10.0fc "" "")) ///
	refcat(e_ols "OLS" e_iv "2SLS", nolabel)